//@author A0105602X
#include "XpensItem.h"

void XpensItem::writefile(char* filename){
	ofstream outfile(filename,ios::app);
	Item::writefile(filename);
	outfile<< venue;
	int i;
	for (i = 0; i< maxnlength + 1 - venue.length(); i ++)
		outfile << ' ';
	outfile.flush();
	outfile.close();
}

void XpensItem::print(){
	Item::print();
	cout << '|' << venue << endl;
	cout << "-------------------------------------------------------------------------------\n";
}

bool XpensItem::recordExtra(){
	cout << "Venue:\n";
	getline(cin,venue);
	while ( venue.length() > maxnlength ) {
		cout << "Length should not exceed " << maxnlength << ". Press Enter to exit.\n";
		getline(cin,venue);
		if (venue == "\n") return false; }
	return true;
}

bool XpensItem::isexpense(){
	return true;
} 

void XpensItem::record_from_file(ifstream& infile, streampos address)
{
	Item::record_from_file(infile,address);
	venue = "";
	char last, c;
	int i;
	last = ' ';
	for (i = 0; i < maxnlength; i ++) {
		infile.get(c);
		if (! ((last == c) && (c == ' '))) venue = venue + c;
		last = c;
	}
	if (venue[venue.length() - 1] == ' ') venue.erase(venue.end() - 1);
	infile.get(c);
}

bool XpensItem::compare(Item& newSpec){
	if (!newSpec.isexpense()) return false;
	if (!Item::compare(newSpec)) return false;
	if (venue == newSpec.getVenue()) return true;
	return false;
}